package com.xunshibao.tutor.common;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xunshibao.core.dao.BaseDAO;
import com.xunshibao.tutor.po.Area;

@Repository
public class AreaDaoImpl {
	private static final String SELECT_BY_CODE = "select spe,code,name from c_area where tp=?";
	private static final String SELECT_BY_CODE_PID = "select id,code,name from c_area where tp=? and pid=?";
	private static final String GET = "select name, code from c_area where tp=? and code=?";
	public List<Area> getAreaByType(Area.TYPE tp){
		return BaseDAO.queryForList(Area.class, SELECT_BY_CODE, new Object[]{tp.value()});
	}
	
	public List<Area> getAreaByTypeAndParentCode(Area.TYPE tp, Integer parentCode) {
		if(parentCode == null || parentCode == 0) {
			return getAreaByType(tp);
		} else {
			return BaseDAO.queryForList(Area.class, SELECT_BY_CODE_PID, new Object[]{tp.value(), parentCode});
		}
	}
	
	public Area getAreaByType(Integer code, Area.TYPE tp){
		return BaseDAO.queryForObject(Area.class, GET, new Object[]{tp.value(), code});
	}
}
